home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Fight / fight.jar / EnemyObject.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-09-16  |  5.7 KB  |  410 lines

  1. import java.util.Random;
  2.  
  3. public class EnemyObject {
  4.    final int STAND = 0;
  5.    final int WALK = 1;
  6.    final int JUMP = 2;
  7.    final int CROUCH = 3;
  8.    final int ATTACK = 4;
  9.    final int CROUCH_ATTACK = 5;
  10.    final int HIT = 6;
  11.    final int CROUCH_HIT = 7;
  12.    FightCanvas parent;
  13.    static Random rand = new Random();
  14.    // $FF: renamed from: x int
  15.    int field_0;
  16.    // $FF: renamed from: y int
  17.    int field_1;
  18.    int state;
  19.    int interval;
  20.    int walking;
  21.    int stop_walking;
  22.    int walk_state;
  23.    int stand_state;
  24.    boolean crouching;
  25.    boolean jump_up;
  26.    int jump_attack_state;
  27.    int jump_pos;
  28.    int attack_dur;
  29.    int attack_type;
  30.    boolean blocking;
  31.    boolean attacking = false;
  32.    public byte energy = 25;
  33.    public byte power = 3;
  34.    public byte speed = 3;
  35.    public byte jump = 10;
  36.    int hit_dur;
  37.    boolean hit_jump;
  38.  
  39.    public EnemyObject(FightCanvas var1) {
  40.       this.parent = var1;
  41.       this.init();
  42.    }
  43.  
  44.    public void setSkills(byte[] var1) {
  45.       this.energy = var1[0];
  46.       this.power = var1[1];
  47.       this.speed = var1[2];
  48.       this.jump = var1[3];
  49.    }
  50.  
  51.    public void cpuMove() {
  52.       if (this.interval % 3 == 0) {
  53.          int var1 = rand.nextInt() % 9;
  54.          if (var1 >= 0) {
  55.             switch (var1) {
  56.                case 0:
  57.                   this.stepLeft();
  58.                   break;
  59.                case 1:
  60.                   this.stepRight();
  61.                   break;
  62.                case 2:
  63.                   this.jump();
  64.                   break;
  65.                case 3:
  66.                   this.crouchStart();
  67.                   break;
  68.                case 4:
  69.                   this.attack(0);
  70.                   break;
  71.                case 5:
  72.                   this.attack(2);
  73.                   break;
  74.                case 6:
  75.                   this.attack(1);
  76.                   break;
  77.                case 7:
  78.                   this.attack(3);
  79.                   break;
  80.                case 8:
  81.                   this.block();
  82.             }
  83.  
  84.          }
  85.       }
  86.    }
  87.  
  88.    public void init() {
  89.       this.state = 0;
  90.       this.field_0 = 0;
  91.       this.field_1 = 48;
  92.       this.walk_state = 0;
  93.       this.stand_state = 0;
  94.       this.stop_walking = 0;
  95.       this.jump_pos = 0;
  96.       this.blocking = false;
  97.       this.attacking = false;
  98.    }
  99.  
  100.    public boolean isHit() {
  101.       return this.state == 6 || this.state == 7;
  102.    }
  103.  
  104.    public void checkRange() {
  105.       if (this.field_0 > this.parent.playerSpr.getXPosition() - 5) {
  106.          this.field_0 = this.parent.playerSpr.getXPosition() - 5;
  107.       }
  108.  
  109.       if (this.field_0 < 0) {
  110.          this.field_0 = 0;
  111.       }
  112.  
  113.       if (this.field_0 > 65) {
  114.          this.field_0 = 65;
  115.       }
  116.  
  117.    }
  118.  
  119.    static int abs(int var0) {
  120.       return var0 < 0 ? -var0 : var0;
  121.    }
  122.  
  123.    public void attack(int var1) {
  124.       switch (this.state) {
  125.          case 0:
  126.          case 1:
  127.             this.state = 4;
  128.             this.attack_dur = 2;
  129.             switch (var1) {
  130.                case 0:
  131.                   this.attack_type = 1;
  132.                   return;
  133.                case 1:
  134.                   this.attack_type = 0;
  135.                   return;
  136.                case 2:
  137.                   this.attack_type = 1;
  138.                   return;
  139.                case 3:
  140.                   this.attack_type = 0;
  141.                   return;
  142.                default:
  143.                   return;
  144.             }
  145.          case 2:
  146.             if (this.walking != 0) {
  147.                this.jump_attack_state = 1;
  148.             } else {
  149.                this.jump_attack_state = 2;
  150.             }
  151.             break;
  152.          case 3:
  153.             this.state = 5;
  154.             this.attack_dur = 3;
  155.             switch (var1) {
  156.                case 0:
  157.                   this.attack_type = 0;
  158.                   break;
  159.                case 1:
  160.                   this.attack_type = 1;
  161.                   break;
  162.                case 2:
  163.                   this.attack_type = 1;
  164.                   break;
  165.                case 3:
  166.                   this.attack_type = 0;
  167.             }
  168.       }
  169.  
  170.    }
  171.  
  172.    public void block() {
  173.       switch (this.state) {
  174.          case 0:
  175.          case 1:
  176.             this.attack_dur = 4;
  177.             this.state = 4;
  178.             this.attack_type = 2;
  179.          case 2:
  180.          default:
  181.             break;
  182.          case 3:
  183.             this.attack_dur = 4;
  184.             this.state = 5;
  185.             this.attack_type = 2;
  186.       }
  187.  
  188.    }
  189.  
  190.    public void hit() {
  191.       switch (this.state) {
  192.          case 0:
  193.          case 1:
  194.             this.state = 6;
  195.             this.hit_dur = 4;
  196.             break;
  197.          case 2:
  198.             this.hit_jump = true;
  199.             break;
  200.          case 3:
  201.             this.state = 7;
  202.             this.hit_dur = 5;
  203.       }
  204.  
  205.    }
  206.  
  207.    public void crouchStart() {
  208.       if (this.state != 2) {
  209.          if (this.crouching) {
  210.             this.state = 1;
  211.             this.crouching = false;
  212.          } else {
  213.             this.state = 3;
  214.             this.crouching = true;
  215.          }
  216.  
  217.       }
  218.    }
  219.  
  220.    public void stepLeft() {
  221.       this.walking = -1;
  222.       if (this.state == 2) {
  223.          this.walking = -3;
  224.       }
  225.  
  226.       this.walk_state = 1;
  227.       --this.stop_walking;
  228.    }
  229.  
  230.    public void stepRight() {
  231.       this.walking = 1;
  232.       if (this.state == 2) {
  233.          this.walking = 3;
  234.       }
  235.  
  236.       this.walk_state = 0;
  237.       --this.stop_walking;
  238.    }
  239.  
  240.    public void walkReset() {
  241.       if (this.crouching) {
  242.          this.state = 3;
  243.       } else if (this.walking == 0) {
  244.          this.state = 0;
  245.       } else {
  246.          this.state = 1;
  247.       }
  248.  
  249.       this.hit_jump = false;
  250.       this.stop_walking = 0;
  251.    }
  252.  
  253.    public void jump() {
  254.       switch (this.state) {
  255.          case 0:
  256.          case 1:
  257.          case 3:
  258.             this.jump_up = true;
  259.             this.jump_attack_state = 0;
  260.             this.state = 2;
  261.             this.crouching = false;
  262.          case 2:
  263.          default:
  264.       }
  265.    }
  266.  
  267.    public void run() {
  268.       ++this.interval;
  269.       switch (this.state) {
  270.          case 0:
  271.          case 1:
  272.             if (this.walking != 0) {
  273.                this.state = 1;
  274.                ++this.walk_state;
  275.                if (this.stop_walking >= 0 && (this.walk_state + 1) % 2 == 0) {
  276.                   this.walking = 0;
  277.                }
  278.  
  279.                this.field_0 += this.walking * this.speed;
  280.                this.checkRange();
  281.             } else {
  282.                this.state = 0;
  283.                if (this.interval % 2 == 0) {
  284.                   ++this.stand_state;
  285.                }
  286.             }
  287.             break;
  288.          case 2:
  289.             if (this.hit_jump) {
  290.                this.field_0 += -this.speed;
  291.             }
  292.  
  293.             if (this.jump_up) {
  294.                this.jump_pos += this.jump;
  295.                if (this.jump_pos >= 2 * this.jump) {
  296.                   this.jump_up = false;
  297.                   ++this.jump_pos;
  298.                }
  299.             } else {
  300.                this.jump_pos -= this.jump;
  301.                if (this.jump_pos <= 0) {
  302.                   this.jump_pos = 0;
  303.                   this.walking = 0;
  304.                   this.walkReset();
  305.                }
  306.             }
  307.  
  308.             this.field_0 += this.walking * this.speed;
  309.          case 3:
  310.          default:
  311.             break;
  312.          case 4:
  313.             --this.attack_dur;
  314.             if (this.attack_dur == 0) {
  315.                this.walkReset();
  316.             }
  317.             break;
  318.          case 5:
  319.             --this.attack_dur;
  320.             if (this.attack_dur == 0) {
  321.                this.walkReset();
  322.             }
  323.             break;
  324.          case 6:
  325.             this.field_0 -= this.speed;
  326.             --this.hit_dur;
  327.             if (this.hit_dur == 0) {
  328.                this.walkReset();
  329.             }
  330.             break;
  331.          case 7:
  332.             --this.hit_dur;
  333.             this.field_0 -= this.speed;
  334.             if (this.hit_dur == 0) {
  335.                this.walkReset();
  336.             }
  337.       }
  338.  
  339.       this.checkRange();
  340.       if (this.state != 4 && this.state != 5) {
  341.          this.attacking = false;
  342.       } else {
  343.          this.attacking = true;
  344.       }
  345.  
  346.       if ((this.state != 5 || this.attack_type != 2) && (this.state != 4 || this.attack_type != 2)) {
  347.          this.blocking = false;
  348.       } else {
  349.          this.blocking = true;
  350.          this.attacking = false;
  351.       }
  352.  
  353.       this.setPlayerFrame();
  354.    }
  355.  
  356.    public void setPlayerFrame() {
  357.       int var1;
  358.       var1 = 0;
  359.       label29:
  360.       switch (this.state) {
  361.          case 0:
  362.             var1 = this.stand_state % 2;
  363.             break;
  364.          case 1:
  365.             var1 = this.walk_state % 2 + 2;
  366.             break;
  367.          case 2:
  368.             if (this.hit_jump) {
  369.                var1 = 7;
  370.             } else if (this.jump_up) {
  371.                switch (this.jump_attack_state) {
  372.                   case 2:
  373.                      var1 = 14;
  374.                      break label29;
  375.                   default:
  376.                      var1 = 12;
  377.                }
  378.             } else {
  379.                switch (this.jump_attack_state) {
  380.                   case 0:
  381.                      var1 = 13;
  382.                      break label29;
  383.                   case 1:
  384.                      var1 = 14;
  385.                      break label29;
  386.                   case 2:
  387.                      var1 = 15;
  388.                }
  389.             }
  390.             break;
  391.          case 3:
  392.             var1 = 8;
  393.             break;
  394.          case 4:
  395.             var1 = this.attack_type + 4;
  396.             break;
  397.          case 5:
  398.             var1 = this.attack_type + 9;
  399.             break;
  400.          case 6:
  401.             var1 = 7;
  402.             break;
  403.          case 7:
  404.             var1 = 12;
  405.       }
  406.  
  407.       this.parent.enemySpr.setFrame(var1);
  408.    }
  409. }
  410.